import { defineStore } from 'pinia'
import { Names } from './store-name'
import { Local } from '@/utils/storage'

export const useLayoutConfigStore = defineStore(Names.LayoutConfig, {
  state: (): LayoutConfigState => {
    return {
      isCollapse: false,
      globalTitle: '航顺芯片官网',
      isFullscreen: false, //是否全屏
      isDrak: false //是否暗黑主题
    }
  },
  getters: {

  },
  actions: {
    updateState(state: LayoutConfigState) {
      // 讲传递的对象属性更新到state状态中
      this.$patch(state)
    }
  }
})

nextTick(() => {
  const layoutConfig = useLayoutConfigStore()
  // 监听状态变化
  layoutConfig.$subscribe((_mutation, state) => {
    // console.log('mutation, state', mutation, state);
    // 保存到本地
    Local.set('layoutConfig', state)
  })
})